import 'package:demo/model/book_cell.dart';
import 'package:demo/util/util.dart';
import 'package:demo/widgets/in_text_dot.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class BookListCell extends StatelessWidget {
  final BookCell cellData;

  const BookListCell({Key key, this.cellData}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final Color accentColor = Theme.of(context).accentColor;
    final Color primaryColor = Colors.blueAccent;

    return InkWell(
      onTap: (){

      },
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: Util.setPercentage(0.03, context), vertical: 15.0),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(color: accentColor, width: 0.5)
          )
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Container(
                padding: EdgeInsets.only(
                    right: Util.setPercentage(0.03, context)
                ),
                child: Image.network(
                  cellData.img,
                fit: BoxFit.contain,
                width: Util.setPercentage(0.2, context),
                height: 100,
              ),
            ),
            Container(
              width: Util.setPercentage(0.5, context),
              margin: EdgeInsets.only(
                right: Util.setPercentage(0.01, context)
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  InkWell(
                    child: Text(
                      cellData.title,
                      style: TextStyle(
                          color: Color(0xFF34383B),
                          fontSize: 18,
                          fontWeight: FontWeight.bold
                      ),
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                    ),
                    onTap: () {
                      print("click ${cellData.id}");
                    },
                  ),
                  SizedBox(
                    height: 5,
                  ),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                     Container(
                       child: CircleAvatar(
                         radius: 10,
                         backgroundImage: NetworkImage(cellData.avatarLarge),
                       ),
                       margin: EdgeInsets.only(right: 5),
                     ),
                      Text(
                        cellData.userName,
                        style: TextStyle(color: Color(0xFF34383B), fontSize: 16.0),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 5.0,
                  ),
                  Row(
                    children: <Widget>[
                      Text(
                        '${cellData.sectionCount}小节',
                        style: TextStyle(color: accentColor),
                      ),
                      InTextDot(),
                      Text(
                        '${cellData.buyCount}人已购买',
                        style: TextStyle(color: accentColor),
                      )
                    ],
                  )
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 5.0),
              decoration: BoxDecoration(
                color: Color(0xFFF0F7FF),
                borderRadius: BorderRadius.all(Radius.circular(15.0))
              ),
              child: Text(
              '￥${cellData.price}',
              style: TextStyle(color: primaryColor, fontSize: 16.0),
              )
            )
          ],
        ),
      ),
    );
  }
}
